package com.study.spmongodb.java8.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author MI
 * @version 1.0
 * @date 2020/12/17 22:32
 */
public class PredicateDemo {

    public static <T> List<T> filter(List<T> list, Predicate<T> p) {
        final ArrayList<T> results = new ArrayList<>();

        for (T s : list) {
            if (p.test(s)) {
                results.add(s);
            }
        }
        return results;
    }

    public static void main(String[] args) {
        final List<String> list = Arrays.asList("hello", "scala");
        Predicate<String> nonEmptyStringPredicate = (String s) -> !s.isEmpty();
        final List<String> filter = filter(list, nonEmptyStringPredicate);
    }
}
